import base from '@/utils/base.js';

// +----------------------------------------------------------------------
// | 辅助方法
// +----------------------------------------------------------------------

/**
 * 格式化参数
 */
function mapConstant(constant) {
    if (base.isEmpty(constant)) return {};
    const temp = {};
    for (let key in constant) {
        key !== '_MAP' && (temp[constant[key]['name']] = constant[key]['desc']);
    }
    return temp;
}

/**
 * 通过constant获取map映射
 * @param constant
 * @returns {{}}
 */
function getMap(constant) {
    return Object.keys(constant[Symbol('MAP')] || {}) > 0 ? constant[Symbol('MAP')] : constant[Symbol('MAP')] = mapConstant(constant);
}

/**
 * 通用状态
 * @type {Array}
 */
export const COMMON_STATE = {
    NORMAL: { name: '1', desc: '正常' },
    ABNORMAL: { name: '0', desc: '禁用' }
};
export const COMMON_STATE_MAP = getMap(COMMON_STATE);

/**
 * 验证码
 * @type {{name: string, desc: string}}
 */
export const CAPTCHA = { name: `${base.requestUrl()}/BSCapCode`, desc: '验证码' };

/**
 * 是否已登录
 * @type {{YES: {name: number, desc: string}, NO: {name: number, desc: string}}}
 */
export const IS_LOGIN = {
    YES: { name: 1, desc: '已登录' },
    NO: { name: 2, desc: '未登录' }
};

/**
 * 是否超级管理员
 * @type {{YES: {name: number, desc: string}, NO: {name: number, desc: string}}}
 */
export const IS_SUPPER = {
    YES: { name: 1, desc: '是' },
    NO: { name: 2, desc: '否' }
};